package com.supor.aiot.common.interfaces;

import android.view.View;

/**
 * ---------------------------------------------------------------- <br>
 * Copyright (C) 2014-2019, by het, Shenzhen, All rights reserved.  <br>
 * ---------------------------------------------------------------- <br>
 * <p>
 * 描述: CustomClickListener <br>
 * 作者: lei <br>
 * 日期: 2020/3/12 <br>
 */
public abstract class CustomClickListener implements View.OnClickListener {
    private long mLastClickTime;
    private long timeInterval = 1000L;

    public CustomClickListener() {

    }

    public CustomClickListener(long interval) {
        this.timeInterval = interval;
    }

    @Override
    public void onClick(View v) {
        long nowTime = System.currentTimeMillis();
        if (nowTime - mLastClickTime > timeInterval) {
            // 单次点击事件
            onSingleClick(v);
            mLastClickTime = nowTime;
        } else {
            // 快速点击事件
            onFastClick(v);
        }
    }

    public void cleanTime() {
        mLastClickTime = 0;
    }

    protected abstract void onSingleClick(View v);

    protected void onFastClick(View v){};
}
